package com.qf.java2201.edu.userservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.java2201.edu.userservice.mapper.UserMapper;
import com.qf.java2201.edu.userservice.pojo.User;
import com.qf.java2201.edu.userservice.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @date 2022/5/28
 * @desc
 */
@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public Page<User> queryPage(Map<String, Object> params) {
        Integer current = (Integer) params.get("page");
        Integer limit = (Integer) params.get("limit");
        Page<User> page = new Page<>(current, limit);

        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        String key = (String) params.get("key");
        queryWrapper.like(User::getRealname,key).or().like(User::getPhone,key);
        Page<User> result = this.page(page, queryWrapper);
        return result;
    }



    //根据用户名 查询用户信息
    @Override
    public User findUserByUserName(String username) {
        //认证 查询数据库
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(User::getUsername,username);

        User user = userMapper.selectOne(wrapper);


        return user;
    }
}
